<!DOCTYPE html>
<div id="file_table2_div">	
		<!-- 查询窗口 -->
		<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
           	<div class="modal-dialog" role="document">
                <div class="modal-content">
	                <div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">查询</h4>
	                </div>
	               	<form action="#" id="mySearch">
	               	<div class="modal-body">
	            	<!-- 以下为要查询的的内容 -->
					<div class="form-group">
						<label for="txt_parent">所属部门</label>
							<input name="userDept"
								class="form-control" id="txt_parent" data-bind="value:queryCondition.userDept" placeholder="部门" >
					</div>
					<div class="form-group">
	                        <label for="search_fileTitle">文件标题</label>
	                        <input id="search_fileTitle" type="text" class="form-control" name="fileTitle" data-bind="value:queryCondition.fileTitle" placeholder="文件标题">
	                    </div>
	                    <div class="form-group">
	                        <label for="search_fileUser">上传者</label>
	                        <input id="search_fileUser" type="text" class="form-control" name="fileUser" data-bind="value:queryCondition.fileUser" placeholder="上传者">
	                    </div>
	                <!-- 以上为要查询的内容 -->
					</div>
					</form>
					<div class="modal-footer">
		                <button type="button" class="btn btn-primary" data-dismiss="modal"	onclick="queryClick()"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>&nbsp;查询</button>
		                <button type="button" class="btn btn-default" data-dismiss="modal" 	onclick="cleanClick()"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;清空</button>
	            	</div>
                </div>
                
           	</div>
		</div> 
		
		<!-- 工具栏 -->
		<div id="toolbar" class="btn-group">
			<button data-bind="click:addClick" type="button"
				class="btn btn-default">
				<span class="glyphicon glyphicon-open" aria-hidden="true"></span> 上传文件
			</button>
 			<button data-bind="click:editClick" type="button"
				class="btn btn-default">
				<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改信息
			</button>
			<button data-bind="click:deleteClick" type="button"
				class="btn btn-default">
				<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 删除文件
			</button>
			<button data-bind="click:searchClick" type="button"
				class="btn btn-default">
				<span class="glyphicon glyphicon-search" aria-hidden="true"></span> 筛选
			</button>
		</div>
		
		<table id="fileTable" data-bind="bootstrapTable:$root" style="table-layout: fixed;">
			<thead>
				<tr>
					<th data-checkbox="true"></th>
					<th data-field="fileTitle"  class="text-center">文件标题</th>
					<!-- <th data-field="uploadsUsername"  class="text-center">上传者</th> -->
					<th data-field="deptName" class="text-center">所属部门</th>
					<th data-field="fileNature" data-formatter="fileNatureFormatter" class="text-center">共享种类</th>
					<th data-field="uploadsName"  class="text-center">上传者姓名</th>
					<th data-field="updateTime"  class="text-center">修改时间</th>
					<th data-field="fileSize"  class="text-center">文件大小</th>
					<th data-field="fileRemark"  class="text-center">文件备注</th>
					<th data-field="download" data-formatter="download" class="text-center">操作</th>
				</tr>
			</thead>
</table>
</div>

<script type="text/javascript">


$(function(){
    var data =  {
		    tableParams : {
		    	url : 'sysFile/page'
		    	},
		    	urls : {
		    		delete : 'sysFile/delete',
		    		update : 'sysFile/edit',
		    		add : 'sysFile/edit',
		    		search:'sysFile/search'
		    	},
 		    	queryCondition : {
 		    		fileTitle : '',
 		    		fileUser : '',
 		    		userDept : ''
		    	}
		};
		ko.applyBindings(new BsTableViewModel(data),document.getElementById('file_table2_div'));	
		
		$('#txt_parent').bootstrapCombotree({
			url:'sysDept/treedata?id='
		});
});

function fileNatureFormatter(value,row,index){
	return value?value.name.substr(0,4):'';	
}

function download(value, row, index){
	var fileUuid = row.fileUuid;
	var html = "<a href='#' onclick='getFile(\"" + fileUuid + "\")'><span class='glyphicon glyphicon-save'></span> </a>";
/* 	var html2 ="<a href='#' onclick='getQrCode(\"" + fileUuid + "\")'><span class='glyphicon glyphicon-align-justify'></span> </a>"; */
	return html;
}


//下载事务处理
function getFile(fileUuid){
	$.ajax({ 
        url: "sysFile/download",  
        type: "POST",  
        data: {
        	"fileUuid":fileUuid
        },  
        success:function(result){
      	  if(result.success==null){
      		location.href="sysFile/download2?fileUuid="+fileUuid;
      	  }else{
      		 bootbox.alert(result.msg);
      	  }
        }
      });  
}

/* //生成二维码
function getQrCode(fileUuid){
	bootbox.dialog({
		message:"<>"
	});
} */

//自定义查询与清空条件
function queryClick(){
	    var opt = {
	            url: "sysFile/page",
	            silent: true,
	            query:{
	            	userDept:$("#txt_parent").val()
	            }
	        };
	        $("#fileTable").bootstrapTable('refresh', opt);
}


function cleanClick(){
	var that = this;
	$("#mySearch").find('*').each(function(){
 		if($(this).is("input")) {
 			$(this).val('').trigger('change');
		}
	}); 
   
	$("#fileTable").bootstrapTable('refresh');
}
</script>